<!DOCTYPE html> <title>Arrow Visual Test</title>

<style>
  @import '/reset.css';
  .scroll {
    overflow: scroll;
    width: 300px;
    height: 300px;
    background-color: grey;
  }

  .scroll::before {
    content: 'before';
    display: block;
    height: 300px;
    width: 1px;
  }

  .scroll::after {
    content: 'after';
    display: block;
    height: 300px;
    width: 1px;
  }

  #reference {
    width: 200px;
    height: 200px;
    background-color: red;
    box-shadow: inset 0 0 0 1px black;
  }

  #popper {
    width: 100px;
    height: 100px;
    background-color: rebeccapurple;
    border: 10px solid;
  }

  #arrow::before {
    content: '';
    display: block;
    width: 20px;
    height: 20px;
    width: 20px;
    height: 20px;
    background-color: yellow;
  }

  #arrow[data-hide]::before {
    opacity: 0;
  }
</style>

<div class="scroll">
  <div id="reference">Reference Box</div>
  <div id="popper">
    Popper Box
    <div id="arrow" data-popper-arrow></div>
  </div>
</div>

<script type="module">
  import { createPopper } from '../../dist/popper.js';
  const reference = document.querySelector('#reference');
  const popper = document.querySelector('#popper');

  window.instance = createPopper(reference, popper, {
    placement: 'right',
    modifiers: [
      {
        name: 'applyArrowHide',
        enabled: true,
        phase: 'write',
        fn({ state }) {
          if (state.modifiersData.arrow.centerOffset !== 0) {
            state.elements.arrow.setAttribute('data-hide', '');
          } else {
            state.elements.arrow.removeAttribute('data-hide');
          }
        },
      },
      {
        name: 'preventOverflow',
        options: {
          tether: false,
        },
      },
    ],
  });
</script>
